package edu.nf.vac.api.controller;

import edu.nf.vac.api.vo.NeedleNumVO;
import edu.nf.vac.api.vo.ResultVO;
import edu.nf.vac.vaccination.dto.NeedleNumDTO;
import edu.nf.vac.vaccination.dto.PeriodDTO;
import edu.nf.vac.vaccination.inf.NeedleNumService;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;

/**
 * @author LQJ
 * @date 2022/3/31
 */
@Api
@RestController
@RequestMapping("/api/v1")
public class NeedleNumController extends BaseController{
    @DubboReference(interfaceClass = NeedleNumService.class,
            version = "1.0.0", check = false)
    private NeedleNumService service;
    @GetMapping("/needlenm/search")
    @ApiOperation(value = "根据发放的疫苗针次搜索接种点",httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200, message = "返回搜索结果", response = ResultVO.class),
            @ApiResponse(code = 500, message = "服务异常")
    })
    public ResultVO<List<NeedleNumVO>> searchNeedleNum(NeedleNumVO vo) {
        NeedleNumDTO dto = BeanUtil.copyProperties(vo, NeedleNumDTO.class);
        List<NeedleNumDTO> dtoList = service.searchNeedleNum(dto);
        List<NeedleNumVO> voList = BeanUtil.copyToList(dtoList, NeedleNumVO.class);
        return success(voList);
    }

    @GetMapping("/needlenum/period/{id}")
    @ApiOperation(value="根据针次ID查询各个接种时段信息", httpMethod = "GET")
    @ApiImplicitParam(name="needleNumId", value="针次ID", required=true, dataTypeClass=Integer.class, paramType="path")
    @ApiResponses({
            @ApiResponse(code = 200, message = "返回当前针次的所有接种时段信息", response = ResultVO.class),
            @ApiResponse(code = 500, message = "服务异常")
    })
    public ResultVO<List<PeriodDTO>> listPeriodByNeedleNumId(@PathVariable("id") Integer needleNumId) {
        List<PeriodDTO> dtoList = service.listPeriodByNeedleNumId(needleNumId);
        return success(dtoList);
    }



}
